package com.gxa.controller.shezhicontroller;

import com.gxa.common.R;
import com.gxa.pojo.KeHu;
import com.gxa.pojo.KeHuType;
import com.gxa.pojo.KeHu_Insert;
import com.gxa.pojo.ZhiYuan;
import com.gxa.service.shezhiservice.KeHuService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author weishen
 */
@RestController
@RequestMapping("/KeHu")
@Api(value = "客户管理" , tags = "客户数据接口API")
@RequiresPermissions("客户管理")
public class KeHuController {

    @Autowired(required = false)
    public R r;
    @Autowired
    public KeHuService keHuService;
    @GetMapping("/selectAllKeHuForPage")
    @ApiOperation(value = "客户查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })

    public R selectAllKeHuForPage(@RequestParam  int page,@RequestParam int size)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        KeHuType keHuType = new KeHuType();
//        keHuType.setKeHuType("vip");
//        List<KeHu> list = new ArrayList<>();
//        KeHu kehu = new KeHu();
//        kehu.setId(1);
//        kehu.setKeHuType(keHuType);
//        kehu.setKeHuBianHao("001");
//        kehu.setKeHuMingCheng("fzw");
//        kehu.setLianXiRen("gd");
//        kehu.setPhone("1899920398");
//        kehu.setZhiWei("测试");
//        kehu.setQiChuMoney(10000);
//        kehu.setQq("123456");
//        kehu.setSongHuoDiZhi("四川成都");
//        kehu.setZhuangTai(1);
//        list.add(kehu);
        return keHuService.selectAllKeHuForPage(page,size);
//        r.setData(list);
    }


    @GetMapping("/selectKeHuByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone")
    @ApiOperation(value = "客户查询接口（根据条件查询）",notes="提供当前页码与每页显示条数，客户类别、编号、名称、联系人、电话任意条件",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "keHuType",value = "客户类别",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "keHuBianHao" ,value="客户编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "keHuMingCheng",value="客户名称",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "lianXiRen",value="联系人",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "phone",value="手机",required = false,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectkeHuByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone(@RequestParam int page,@RequestParam int size,
                                                                   String keHuType,String keHuBianHao,
                                                                   String keHuMingCheng,String lianXiRen,
                                                                   String phone)
    {
        return keHuService.selectKeHuByTypeOrBianHaoOrLianXiRenOrMingChenOrPhone(page,size,keHuType,
                keHuBianHao,keHuMingCheng,lianXiRen,phone);
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        KeHuType keHuType1 = new KeHuType();
//        keHuType1.setKeHuType("vip");
//        List<KeHu> list = new ArrayList<>();
//        KeHu kehu = new KeHu();
//        kehu.setId(1);
//        kehu.setKeHuType(keHuType1);
//        kehu.setKeHuBianHao("001");
//        kehu.setKeHuMingCheng("fzw");
//        kehu.setLianXiRen("gd");
//        kehu.setPhone("1899920398");
//        kehu.setZhiWei("测试");
//        kehu.setQiChuMoney(BigDecimal.valueOf(10000.0));
//        kehu.setQq("123456");
//        kehu.setSongHuoDiZhi("四川成都");
//        list.add(kehu);
//        return r;
    }
    @PostMapping("/insertKeHu")
    @ApiOperation(value = "新增客户接口",notes="提供客户信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertKeHu(@RequestBody KeHu_Insert keHu)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        return r;
        return keHuService.insertKeHu(keHu);
    }

    @PostMapping("/updateKeHuById")
    @ApiOperation(value = "修改客户信息接口",notes="提供客户信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateKeHuById(@RequestBody KeHu keHu)
    {
//        r.setCode(200);
//        r.setMsg("修改成功！");
//        return r;
        return keHuService.updateKeHuById(keHu);
    }

    @PostMapping("/deleteKeHuById")
    @ApiOperation(value = "删除客户接口",notes = "提供客户id",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteKeHuById(@RequestParam ArrayList<Integer> id)
    {
//        r.setCode(200);
//        r.setMsg("删除成功！");
//        return r;
        return keHuService.deleteKeHuById(id);
    }

    @GetMapping("/selectKeHuType")
    @ApiOperation(value = "查询客户类别接口")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectKeHuType()
    {
        r.setCode(200);
        r.setMsg("查询成功！");
        return r;
    }


}
